package mtt.us.client.views.fachbereich.matrikel.editor;

import mtt.us.client.events.GetModelDataEvent;
import mtt.us.client.events.SetModelDataEvent;
import mtt.us.dto.MatrikelDTO;
import hmvc4gwt.client.event.HmvcEvent;
import hmvc4gwt.client.event.HmvcEventListener;
import hmvc4gwt.client.model.Model;

public class MatrikelEditorModel extends Model implements HmvcEventListener {
	
	private MatrikelDTO matrikel;

	public MatrikelEditorModel() {
	}
	
	public MatrikelEditorModel(MatrikelDTO matrikel) {
		setMatrikel(matrikel);
	}
	
	public void doInit() {
		getController().register(GetModelDataEvent.class, this);
	}

	private MatrikelDTO getMatrikel() {
		return matrikel;
	}

	public void handleEvent(HmvcEvent event) {
		
		if (event instanceof GetModelDataEvent) {
			getController().fireLocalEvent(new SetModelDataEvent(getMatrikel()));
			
		} 
	}

	private void setMatrikel(MatrikelDTO matrikel) {
		this.matrikel = matrikel;
	}

}
